﻿using Microsoft.Extensions.Logging;
using System;
using WebApiV3.Data.Entity;
using WebApiV3.Domoin.Enum;
using WebApiV3.Interface.Log;

namespace WebApiV1.Utils.Log
{
    //帮助类
    public static class LogHelper
    {
        //静态方法
        //this拓展方法
        public static void Logger(this ILog log, Exception exception, Loglevel logsLevel, int userId)
        {
            var item = new Logs
            {
                LogLevel = (int)logsLevel,
                ShoreMessage = exception.Message,
                FullMessage = exception.ToString(),
                UserId = userId
            };
            log.Insert(item);
        }

        public static void Info(this ILog log, Exception exception, Loglevel logLevel = Loglevel.信息, int userId = 0)
        {
            Logger(log, exception, logLevel, userId);
        }

        public static void Debug(this ILog log, Exception exception, Loglevel logLevel = Loglevel.调试, int userId = 0)
        {
            Logger(log, exception, logLevel, userId);
        }

        public static void Warn(this ILog log, Exception exception, Loglevel logLevel = Loglevel.警告, int userId = 0)
        {
            Logger(log, exception, logLevel, userId);
        }

        public static void Error(this ILog log, Exception exception, Loglevel logLevel = Loglevel.错误, int userId = 0)
        {
            Logger(log, exception, logLevel, userId);
        }
        public static void Fatal(this ILog log, Exception exception, Loglevel logLevel = Loglevel.崩溃, int userId = 0)
        {
            Logger(log, exception, logLevel, userId);
        }
    }
}
